package com.ax.base.drugadministration.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ax.base.common.utils.AjaxRes;
import com.ax.base.common.utils.Const;
import com.ax.base.common.utils.PageUtils;
import com.ax.base.drugadministration.domain.BaseDrugManager;
import com.ax.base.drugadministration.service.DrugAdministrationManagerService;

@Controller
@RequestMapping("/sys/drugAdministrationManager")
public class DrugAdministrationManagerController {

	@Autowired
	DrugAdministrationManagerService drugAdministrationManagerService;
	
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping()
	String drugAdministration(Model model) {
		return "drugAdministration/drugmanager/drugadmanager";
	}
	
	/**
	 * 药监查询(模块:药监人员)*包含该人的药监部门信息
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryDrugAdministrationManager")
	@ResponseBody
	public List<BaseDrugManager> queryDrugAdministrationManager(@RequestParam Map<String, Object> params) {
		 //PageUtils drugAdministrationManagers = this.drugAdministrationManagerService.queryDrugAdministrationManagerSer(params);
		   List<BaseDrugManager> BaseDrugManagers = this.drugAdministrationManagerService.queryDrugAdministrationManagerSer(params);
		   return BaseDrugManagers;
	  }
	
	/**
	 * 药监增加(模块:药监人员)*跳转增加页面
	 * 
	 * @param Long pId
	 *           
	 * @return HTML
	 */
	@GetMapping("/add")
	String add(Model model) {
		return "drugAdministration/drugmanager/add";
	}
	
	/**
	 * 药监保存(模块:药监人员)
	 * 
	 * @param BaseDrugManager baseDrugManager
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertDrugDepManager")
	@ResponseBody
	public AjaxRes insertDrugManager(AjaxRes ajaxRes,BaseDrugManager baseDrugManager){
		try {
			this.drugAdministrationManagerService.insertDrugManagerSer(baseDrugManager);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 药监修改(模块:药监人员)*跳转修改页面
	 * 
	 * @param Long id
	 *           
	 * @return HTML
	 */
	@GetMapping("/edit/{id}")
	String edit(Model model, @PathVariable("id") Long id) {
		model.addAttribute("manager",drugAdministrationManagerService.getBaseDrugManagerSer(id));
		return "drugAdministration/drugmanager/edit";
	}
	
	/**
	 * 药监修改(模块:药监人员)
	 * 
	 * @param BaseDrugManager baseDrugManager
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateDrugManager")
	@ResponseBody
	public AjaxRes updateDrugManager(AjaxRes ajaxRes,BaseDrugManager baseDrugManager){
		try {
			this.drugAdministrationManagerService.updateDrugManagerSer(baseDrugManager);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 药监修改状态(模块:药监人员)
	 * 
	 * @param drugManagerId,flag
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateState")
	@ResponseBody
	public AjaxRes updateState(AjaxRes ajaxRes,BaseDrugManager baseDrugManager){
		try {
			this.drugAdministrationManagerService.updateStateSer(baseDrugManager);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 编号是否重复(新增)
	 * 
	 * @param Map<String, Object> params
	 *         
	 * @return boolean
	 */
	@PostMapping("/Validate")
	@ResponseBody
	public boolean empnoValidate(@RequestParam Map<String, Object> params){
		return !drugAdministrationManagerService.validateSer(params);
	}
	
	/**
	 * 是否重复(修改)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
	@PostMapping("/updateValidate")
	@ResponseBody
	public boolean updateValidate(String parameter){
		return !drugAdministrationManagerService.updateValidateSer(parameter);
	}
}
